﻿@using Gpsys.Web.Common
@model Gpsys.Web.Models.PortEntityModel
@{
    ViewBag.Title = "Edit Port";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section jsFooter{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#Port_AdapterType').change(function () {
                GetAdapterXml();
            });

            $("input[name='Port.Type']").change(function () {
                GetAdapterXml();
            });
        });

        function GetAdapterXml() {
            var sType = $("input[name='Port.Type']:checked").val();
            var sAdType = $('#Port_AdapterType').val();

            $.getJSON('/Port/GetAdapterXml', { type: sType, adapterType: sAdType}, function (data) {
                $('#Port_Configuration').val(data)
            });
        }
    </script>

}

<div class="mws-panel grid_8">
    <div class="mws-panel-header">
        <span>@ViewBag.FormTitle</span>
    </div>
    <div class="mws-panel-body no-padding">
        @using (Html.BeginForm(ViewBag.IsUpdate ? "Edit" : "Create", "Port", FormMethod.Post, new { @class = "mws-form" }))
        {
            if (ViewBag.Valid == false)
            {
                <div class="mws-form-message error">
                    @Html.ValidationSummary()
                </div>
            }
            @Html.HiddenFor(m => m.Port.Id);
            @Html.HiddenFor(m => m.Port.CreatedBy);
            @Html.HiddenFor(m => m.Port.CreatedOn);
            @Html.HiddenFor(m => m.Port.ModifiedBy);
            @Html.HiddenFor(m => m.Port.ModifiedOn);
            
            <div class="mws-form-inline">
                <div class="mws-form-row">
                    <label class="mws-form-label">
                        Code</label>
                    <div class="mws-form-item small">
                        @Html.TextBoxFor(m => m.Port.Code)
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">
                        Description</label>
                    <div class="mws-form-item large">
                        @Html.TextBoxFor(m => m.Port.Description)
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">
                        Type</label>
                    <div class="mws-form-item large">
                        @Html.RadioButtonFor(m => m.Port.Type, "1") <label>Receive</label> <br />
                        @Html.RadioButtonFor(m => m.Port.Type, "2") <label>Send</label>

                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">
                        Adapter Type</label>
                    <div class="mws-form-item small">
                        @Html.DropDownListFor(m => m.Port.AdapterType, Model.GetAdapterTypeItems())
                    </div>
                </div>
                <div class="mws-form-row">
                    <label class="mws-form-label">
                        Xml</label>
                    <div class="mws-form-item large">
                        @Html.TextArea("Port.Configuration", Model.Port.Configuration.FormatXml(), new { @rows = "100%", @cols = "100%", @style = "height :50em" })
                    </div>
                </div>
                @if (ViewBag.IsUpdate)
                {
                    <div class="mws-form-row">
                        <label class="mws-form-label">
                            Created By</label>
                        <div class="mws-form-item large">
                            @Model.Port.CreatedBy
                        </div>
                    </div>

                    <div class="mws-form-row">
                        <label class="mws-form-label">
                            Created On</label>
                        <div class="mws-form-item large">
                            @Model.Port.CreatedOn
                        </div>
                    </div>

                    <div class="mws-form-row">
                        <label class="mws-form-label">
                            Modified By</label>
                        <div class="mws-form-item large">
                            @Model.Port.ModifiedBy
                        </div>
                    </div>

                    <div class="mws-form-row">
                        <label class="mws-form-label">
                            Modified On</label>
                        <div class="mws-form-item large">
                            @Model.Port.ModifiedOn
                        </div>
                    </div>
                }
            </div>
            <div class="mws-button-row">
                <input type="submit" value="Submit" class="btn btn-danger" />
            </div>
        }
    </div>
</div>
